package vn.student;

import java.util.Date;
import vn.student.controller.ViewDateScheduleController;
import vn.student.mylib.Constants;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.RelativeLayout;

	/*
	
		Class name: ViewDateSchedule.java
		Function: Day la lop ke thua lop Activity, la lop khoi tao cua so Activity dung de xem danh sac lop mon hoc (Class) co trong ngay
			va danh sach bai tap den han nop trong mot ngay xac dinh.
		
	*/

public class ViewDateSchedule  extends Activity{
	Date date = null;
	String dateStr = "";
	ViewDateScheduleController controller = null;
	boolean isEditSomething = false;
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.date_schedule);
		Intent intent = this.getIntent();
		this.dateStr = intent.getExtras().getString("date");
		controller = new ViewDateScheduleController(this,dateStr);
		RelativeLayout tmp = (RelativeLayout) findViewById(R.id.viewAssignmentBtn);
		tmp.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				controller.showDateAssignments();
			}
		});
		tmp = (RelativeLayout) findViewById(R.id.viewClassBtn);
		tmp.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				controller.showDateClass();
			}
		});
		
		tmp = (RelativeLayout) findViewById(R.id.back);
		tmp.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				back();
			}
		});
		controller.showDateClass();
	}
	private void back(){
		if(isEditSomething)
			this.setResult(RESULT_OK);
		else
			this.setResult(RESULT_CANCELED);
		this.finish();
	}
	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		if(requestCode==Constants.ViewAssignmentDetailInPlannerRequestCode){
			if(resultCode==RESULT_OK){
				controller.showDateAssignments();
				isEditSomething = true;
			}
		}
		if(requestCode==Constants.ViewClassDetailRequestCode){
			if(resultCode==RESULT_OK){
				controller.showDateClass();
				isEditSomething = true;
			}
		}
	}
}
